<?php

$server = "172.21.147.31";
$connectionInfo = array( "Database"=>"ss2g6", "UID"=>"ss2g6", "PWD"=>"group6", 'ReturnDatesAsStrings'=> true );
$conn = sqlsrv_connect( $server, $connectionInfo );
    if ($conn == false){
		die( print_r( sqlsrv_errors(), true));
	}

	$params = array();
	$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

    $tables = array(
        "Doctor" => "doctors.php",
        "Patient" => "patients.php",
        "Pharmacy" => "pharmacy.php",
        "PharmaceuticalCompany" => "pharmaceutical.php",
        "Contract" => "contract.php",
        "Drug" => "drugs.php",
        "Prescribes" => "prescribes.php",
        "Sells" => "sells.php",
        "SideEffect" => "sideeffects.php",
        "Supervisor" => "supervisor.php",
        "Ingredient" => "ingredients.php",
    );

    $results = array();

    foreach ($tables as $table_name => $page){
	    $sql = "SELECT COUNT(*) as doctorCount FROM " . $table_name;
        $stmt = sqlsrv_query( $conn, $sql , $params, $options );
        $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
        $results[$table_name] = $row['doctorCount'];
    }
?>


<? include 'html_head.php' ?>
    <? include 'header.php' ?>
    <div class="container-fluid">
      <div class="row-fluid">
        <div class="span2">
			<? include 'sidebar.php' ?>
        </div><!--/span-->
        <div class="span10">
          <h2>Database Overview</h2>
          <div class="row">
        
            <div class="row">
           <? foreach ($tables as $table_name => $page){ ?>
            <div class="span3 well">
                <a href="<? echo $page ?>">
                <h3><? echo $table_name ?></h3></a>
                <? echo $results[$table_name]; ?> records.
            </div>
           <? } ?> 
           </div>
            <div class="span10">
              <h3>Enter your query:</h3>
                    <form method="post" action="custom.php" class="well form-inline">
                    <div class="control-group">
                        <div class="controls">
                            <textarea name="query" class="span9" id="textarea" rows="5" placeholder = 'SQL query'></textarea>
                        </div>
                    </div>
                    <p>
                    <p><input type="submit" name="submit" class="btn btn-primary" href="#" /></p>
                    </form>
                    
            </div><!--/span-->
          </div><!--/row-->
        </div><!--/span-->
      </div><!--/row-->

<? include 'html_tail.php' ?>
